<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            height: 2000px;
        }
        .box1{
            position: relative;
            top: 30px;
            left: 30px;
            margin-top: 300px;
            margin-left: 100px;
            width: 300px;
            height: 300px;
            background-color: aquamarine;
            border: solid 10px red;
        }
        .box{
            position: relative;
            top: 50px;
            background-color: blanchedalmond;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="box1"></div>
    </div>
</body>
<script>
    var box1=document.getElementsByClassName('box1')[0];
    
    //获得元素相对父元素的偏移量(只读)
    console.log(box1.offsetTop,box1.offsetLeft);

    //获取盒子的宽高(边框+内边距+宽/高)
    console.log(box1.offsetWidth,box1.offsetHeight);

    //获取相对定位的父元素
    console.log(box1.offsetParent);

</script>
</html>